<template>
  <el-dialog v-model="visible" width="600px" draggable align-center>
    <el-form ref="formRef" :model="formData" class="p-2" label-width="120px">
      <el-form-item label="备注">
        <el-input v-model="formData.nickName"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="visible = false">取 消</el-button>
        <el-button type="primary" @click="confirm" :loading="confirmLoading">确 定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { ElMessage } from "element-plus";


const visible = ref(false)

const type = ref('')
const formRef = ref()
const formData = ref({})

import request from '@/config/axios'

const confirmLoading = ref(false)

const emit = defineEmits(["ok"])
const confirm = async function () {
  confirmLoading.value = true
  try {
    const url = {
      'add': '/agency/save',
      'bianji': '/agency/updateById',
    }
    const response = await request.post({
      url: url[type.value],
      data: formData.value
    })
  } catch (error) {
    throw error;
  } finally {
    confirmLoading.value = false
    visible.value = false
    emit('ok')
    ElMessage.success("保存成功!")
  }
}





defineExpose({
  add: () => {
    type.value = 'add'
    formData.value = {}
    visible.value = true
  },
  bianji: (row) => {
    visible.value = true
    formData.value = row
    type.value = 'bianji'
  },
})

</script>

<style scoped lang="scss"></style>
